<template>
  <div class="container mtop-20 ">
    <div class="left f-left">
      <div class="header fsize-b mbuttom-10">
        <span @click="back"><i class="el-icon-arrow-left"></i>{{title}}详情</span>
      </div>
      <div class="main">
        <video controls
               :src="mvUrl"></video>
      </div>
      <div class="buttom mtop-10">
        <div class="author"
             v-if="mvList.artists">
          <img v-lazy="mvList.artists[0].img1v1Url"
               class="img-20 f-left ">
          <span class=" ml-12 fs-14">{{ mvList.artists[0].name }}</span>
        </div>
        <div class="author"
             v-if="mvList.creator">
          <img v-lazy="mvList.creator.avatarUrl"
               class="img-20 f-left ">
          <span class=" ml-12 fs-14">{{ mvList.creator.nickname}}</span>
        </div>
        <p class="fsize-b mtop-10 hidden"
           v-if="mvList.artistName">{{ mvList.artistName }}</p>
        <p class="fsize-b mtop-10 hidden"
           v-if="mvList.creator">{{ mvList.description }}</p>
        <div class="time mtop-10 cc fs-12">
          <span v-if="mvList.artistName">发布时间:&nbsp;&nbsp;{{ mvList.publishTime }}</span>
          <span v-if="mvList.creator">发布时间:&nbsp;&nbsp;{{ (mvList.publishTime)|dateFormat }}</span>
          <span class="ml-12"
                v-if="mvList.artistName">播放次数:&nbsp;&nbsp;{{ (mvList.playCount) |changeNum}}</span>
          <span class="ml-12"
                v-if="mvList.creator">播放次数:&nbsp;&nbsp;{{ (mvList.subscribeCount) |changeNum}}</span>
        </div>
      </div>
      <div class="comment">
        <comment :type="resoureType"
                 :id="id"></comment>
      </div>
    </div>
    <div class="right f-left">
      <div class="title">
        <p class="mbuttom-10 fsize-b">相关视频</p>
        <div class="remv">
          <li v-for="item in remvList"
              :key="item.vid"
              @click="goMv(item.vid)">
            <div class="mvimg">
              <img v-lazy="item.coverUrl"
                   class="mbuttom-10">
              <div class="times fs-12"><span>{{  (item.playTime)|timeFormat}}</span></div>
            </div>
            <div class="mvright ml-12">
              <span class="fs-13 ">{{ item.title }}</span>
              <span class="fs-12 c "
                    style="position:relative;top:30px"> by&nbsp;{{ item.creator[0].userName }}</span>
            </div>
          </li>
        </div>
      </div>
    </div>
  </div>
</template>

<script> 
import comment from "@/components/comment/comment"
import { getMvDetail, getMvUrl, getReAllvideo, getDetail, getVideoUrl } from "@/api/video"
export default {
  data () {
    return {
      mvUrl: '',
      mvList: [],
      remvList: [],
      id: '',
      type: '',
    }
  },
  components: { comment },
  mounted () {
    this.getMvDetail(this.$route.query.mvid)
    this.getReAllvideo(this.$route.query.mvid)
    this.id = this.$route.query.mvid
    console.log(this.id, '520000')
  },
  computed: {
    title () {
      return this.type === 'mv' ? 'MV' : '视频'
    },
    resoureType () {
      return this.type === 'mv' ? 1 : 4
    },
  },
  methods: {
    // 后退按钮
    back () {
      this.$router.back()
    },
    // 获取歌单信息
    async getMvDetail (id) {
      if (/^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]+$/.test(id) == false) {
        this.type = 'mv'
        let res = await getMvDetail({ mvid: id })
        if (res.code !== 200) return
        this.mvList = res.data
        this.getMvUrl(id)
      } else {
        this.type = '视频'
        this.getVideoUrl(id)
        this.getDetail(id)
        console.log(this.mvType)
      }

    },
    // 获取相关歌单信息
    async getDetail (id) {
      let res = await getDetail(id)
      if (res.code !== 200) return
      this.mvList = res.data
    },
    // 获取mvurl
    async getMvUrl (id) {
      let res = await getMvUrl({ id: id })
      if (res.code !== 200) return
      this.mvUrl = res.data.url
    },
    // 获取相关视频的url
    async getVideoUrl (id) {
      let res = await getVideoUrl({ id: id })
      if (res.code !== 200) return
      this.mvUrl = res.urls[0].url
    },
    // 获取相关视频
    async getReAllvideo (id) {
      let res = await getReAllvideo(id)
      if (res.code !== 200) return
      this.remvList = res.data
    },
    // 相关视频
    goMv (id) {
      this.getDetail(id)
      this.getVideoUrl(id)
    }
  },

}
</script>

<style scoped lang="less">
.container {
  .left {
    width: 600px;
    height: auto;
    margin-left: 120px;
    .header {
      margin-left: 5px;
      cursor: pointer;
    }
    .main {
      video {
        width: 600px;
        height: 350px;
      }
    }
    .buttom {
      .author {
        span {
          display: inline-block;
          height: 40px;
          line-height: 40px;
          color: #5c6268;
        }
      }
      // .time {
      // }
    }
  }
  .right {
    width: 400px;
    .remv {
      height: 90px;
      li {
        width: 400px;
        display: flex;
        .mvimg {
          img {
            width: 150px;
            height: 90px;
            border-radius: 4px;
          }
          .times {
            position: relative;
            bottom: 30px;
            right: -115px;
            color: #fff;
          }
        }
        .mvright {
          height: 90px;
          width: 160px;
          flex-shrink: 0;
          span {
            max-height: 36px;
            display: flex;
            flex-wrap: wrap;
            text-overflow: ellipsis;
            overflow: hidden;
          }
        }
      }
    }
  }
}
</style>